﻿/**
Name: NewProject.js
Created By: Nikhil
Created on: 14-01-2012
Description: Page level js to be included in newproject.aspx. All the onclick and json data
manipulations will be done in this javascript
**/

/*Document.ready function called on DOM ready*/
$(function() {debugger;
/*setTimeout("Function_Name", 0);
Here here 0 is wait time in ms for function to execute
Function_Name: is name of the function to be called.
Useful in handling asynchronus function calls.
*/
//Calling attach events on load of page
setTimeout("Newproject_AttachEvents()", 0);
    });
    
//**AttachEvents: Function to keep onclick and other events**//
function Newproject_AttachEvents()
{debugger;
//JS added for validation when DOM ready
$("#frmNewProject").validate();
$("#txtStartDate").datepicker();
$("#txtEndDate").datepicker();
$("#TotalTime").click(function() {debugger;
var end=$("#txtEndDate").val();
var start=$("#txtStartDate").val();
CalTimediff(end,start,months);
});
}

//Function to find out difference bettween two dates in form of months years or days
function CalTimediff(date1,date2,months) {debugger;
    var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
    date1 = new Date(date1);
    date2 = new Date(date2);
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    switch (interval) {
        case "years": return date2.getFullYear() - date1.getFullYear();
        case "months": return (
            ( date2.getFullYear() * 12 + date2.getMonth() )
            -
            ( date1.getFullYear() * 12 + date1.getMonth() )
        );
        case "weeks"  : return Math.floor(timediff / week);
        case "days"   : return Math.floor(timediff / day); 
        case "hours"  : return Math.floor(timediff / hour); 
        case "minutes": return Math.floor(timediff / minute);
        case "seconds": return Math.floor(timediff / second);
        default: return undefined;
    }
}